package middleware

import (
	"fx_swift_agent/internal/model"
	"fx_swift_agent/pkg/code"
	"fx_swift_agent/pkg/global"
	"fx_swift_agent/pkg/internalerrors"
	"github.com/gin-gonic/gin"
	"net/http"
)

func AgentFreezeStatus() gin.HandlerFunc {
	var (
		account    string
		accountObj *model.FxAgent
	)
	return func(ctx *gin.Context) {
		account = ctx.Value("Account").(string)
		global.GFDB.Model("fx_agent").Where("account=?", account).Scan(&accountObj)
		if accountObj.IsFreeze == 0 {
			code.Fail(ctx, http.StatusNotAcceptable, internalerrors.New(code.ErrBind, "").Code, "帐号被冻结")
			ctx.Abort()
		}
		ctx.Next()
	}
}
